﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using ProgNetComponents.Design.Attributes;

namespace ProgNetComponents.Controls
{
    /// <summary>
    /// Base component with ICustomTypeDescriptor implementation
    /// </summary>
    public abstract class BaseCustomComponent : Component, ICustomTypeDescriptor
    {
        #region ICustomTypeDescriptor Members
        private bool noCustomTypeDesc = true;
        /// <summary>
        /// Gets Attributes using TypeDescriptor
        /// </summary>
        /// <returns></returns>
        public AttributeCollection GetAttributes()
        {
            return TypeDescriptor.GetAttributes(this, noCustomTypeDesc);
        }

        /// <summary>
        /// Gets class name using TypeDescriptor
        /// </summary>
        /// <returns></returns>
        public string GetClassName()
        {
            return TypeDescriptor.GetClassName(this, noCustomTypeDesc);
        }

        /// <summary>
        /// Gets component name using TypeDescriptor
        /// </summary>
        /// <returns></returns>
        public string GetComponentName()
        {
            return TypeDescriptor.GetComponentName(this, noCustomTypeDesc);
        }
        /// <summary>
        /// Gets converter using TypeDescriptor
        /// </summary>
        /// <returns></returns>
        public TypeConverter GetConverter()
        {
            return TypeDescriptor.GetConverter(this, noCustomTypeDesc);
        }
        /// <summary>
        /// Gets default event using TypeDescriptor
        /// </summary>
        /// <returns></returns>
        public EventDescriptor GetDefaultEvent()
        {
            return TypeDescriptor.GetDefaultEvent(this, noCustomTypeDesc);
        }
        /// <summary>
        /// Gets default property using TypeDescriptor
        /// </summary>
        /// <returns></returns>
        public PropertyDescriptor GetDefaultProperty()
        {
            return TypeDescriptor.GetDefaultProperty(this, noCustomTypeDesc);
        }
        /// <summary>
        /// Gets editor using TypeDescriptor
        /// </summary>
        /// <param name="editorBaseType"></param>
        /// <returns></returns>
        public object GetEditor(Type editorBaseType)
        {
            return TypeDescriptor.GetEditor(this, editorBaseType, noCustomTypeDesc);
        }
        /// <summary>
        /// Gets events using TypeDescriptor and specified attributes
        /// </summary>
        /// <param name="attributes"></param>
        /// <returns></returns>
        public EventDescriptorCollection GetEvents(Attribute[] attributes)
        {
            return TypeDescriptor.GetEvents(this, attributes, noCustomTypeDesc);
        }
        /// <summary>
        /// Gets events using TypeDescriptor
        /// </summary>
        /// <returns></returns>
        public EventDescriptorCollection GetEvents()
        {
            return TypeDescriptor.GetEvents(this, noCustomTypeDesc);
        }
        /// <summary>
        /// Gets Properties using DynamicPropertyAttribute
        /// </summary>
        /// <param name="attributes"></param>
        /// <returns></returns>
        public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
        {
            return GetProperties();
        }
        /// <summary>
        /// Gets Properties using DynamicPropertyAttribute
        /// </summary>
        /// <returns></returns>
        public PropertyDescriptorCollection GetProperties()
        {
            return DynamicPropertyAttribute.GetProperties(this);
        }
        /// <summary>
        /// Gets this object
        /// </summary>
        /// <param name="pd"></param>
        /// <returns></returns>
        public object GetPropertyOwner(PropertyDescriptor pd)
        {
            return this;
        }

        #endregion
    }
}
